using GGameFramework.Event;
using GGameFramework.MInput;
using UnityEngine;
using UnityEngine.InputSystem;

namespace GGameFramework.Runtime
{
    
    public class InputComponent : FrameworkComponent
    {
        public override FrameworkComponentPriority Priority => FrameworkComponentPriority.System;
        

        private PlayerInput _unityPlayerInput;
        public PlayerInput PlayerInput
        {
            get { return _unityPlayerInput; }
        }
        
        private InputManager _inputManager;
        
        protected override void Awake()
        {
            base.Awake();

            // 创建Unity输入组件
            _unityPlayerInput = gameObject.AddComponent<PlayerInput>();
            // _unityPlayerInput.actions = _inputConfig.actionAsset;
            
            // 初始化输入管理器
            _inputManager = FrameworkEntry.GetModule<InputManager>();
            // _inputManager.Initialize(this, _inputConfig);
            
            // // 初始化事件桥接
            // var eventManager = FrameworkEntry.GetModule<EventManager>();
            // new InputEventBridge(_inputManager, eventManager);
        }
        
        

        private void OnDestroy()
        {
            // 清理Unity输入组件
            if (_unityPlayerInput != null)
            {
                Destroy(_unityPlayerInput);
            }
        }

        // public void RebindAction(string actionName, System.Action onComplete) =>
        //     _inputManager.RebindAction(actionName, onComplete);
        //
        // public void ResetInputBindings() =>
        //     _inputManager.ResetToDefaultBindings();
        //
        //
        //
        // public InputAction GetAction(string actionName)
        // {
        //     return _unityPlayerInput.actions.FindAction(actionName);
        // }
        //
        // // 外部接口
        // public void SwitchToKeyboard() => 
        //     _inputManager.SwitchToDevice(GGameFramework.Input.InputDevice.Keyboard);
        //
        // public void SwitchToGamepad() => 
        //     _inputManager.SwitchToDevice(GGameFramework.Input.InputDevice.Gamepad);
        //
        // public bool IsCompositeKeyPressed(string compositeKeyName) => 
        //     _inputManager.IsCompositeKeyPressed(compositeKeyName);
    }
}